package gel;

import static org.junit.Assert.assertTrue;
import gel.test.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * Checks that we win most of the rounds against RamFire. Also checks that we lead in score as well.
 * 
 * @author George Lee
 * 
 */
public class TestMenehuneVersusRamFire extends RobotTestBed {
  /** Check that we win at least 60% of the time. */
  private static final double WIN_THRESHOLD = 0.6;

  /**
   * Specifies that SittingDuck and Menehune are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.RamFire,gel.Menehune";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * The actual test, which asserts that DaCruzer has won every round against SittingDuck.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    BattleResults ramFireResults = event.getIndexedResults()[0];
    BattleResults menehuneResults = event.getIndexedResults()[1];

    // Check to make sure Menehune is ahead of the threshold.
    double winPercentage = (double) menehuneResults.getFirsts() / (double) getNumRounds();
    assertTrue("Check Menehune win percentage", winPercentage >= WIN_THRESHOLD);

    // Check that Menehune leads in points as well.
    assertTrue("Check Menehune score", menehuneResults.getScore() > ramFireResults.getScore());
  }
}
